package ynu.czs.controller;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import ynu.czs.entity.Cart;
import ynu.czs.entity.User;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {
    @Resource
    private RestTemplate restTemplate;

    @GetMapping("/getCartById/{userId}")
    public Cart getCartById(@PathVariable("userId") Integer userId) {
        Cart cart = new Cart();
        List<String> goods = new ArrayList<>();
        goods.add("电池");
        goods.add("充电器");
        goods.add("手机壳");
        cart.setGoodList(goods);
        User u = restTemplate.getForObject("http://localhost:10000/user/getUserById/"+userId, User.class);
        cart.setUser(u);
        return cart;

    }
}
